﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
using System.Configuration;

namespace ZG_member.DAL
{
	/// <summary>
	/// 数据访问类:consumeSolution
	/// </summary>
	public partial class consumeSolution
	{
		public consumeSolution()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("id", "consumeSolution"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from consumeSolution");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
			parameters[0].Value = id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}
        public bool Updatepoint(string taocan, string id,double money)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update consumeSolution set ");
            strSql.Append("taocanxiangqin=@taocanxiangqin , money=@money where id = @id");
            SqlParameter[] parameters = {					
					new SqlParameter("@taocanxiangqin", SqlDbType.NVarChar,4000),
                    new SqlParameter("@money", SqlDbType.Money,8),
                                        new SqlParameter("@id", SqlDbType.NVarChar,200)};
            parameters[0].Value = taocan;
            parameters[1].Value = money;
            parameters[2].Value = id;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool Updatepoint(string taocan, string id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update consumeSolution set ");
            strSql.Append("taocanxiangqin=@taocanxiangqin  where id = @id");
            SqlParameter[] parameters = {					
					new SqlParameter("@taocanxiangqin", SqlDbType.NVarChar,4000),
                    new SqlParameter("@money", SqlDbType.Money,8),
                                        new SqlParameter("@id", SqlDbType.NVarChar,200)};
            parameters[0].Value = taocan;
  
            parameters[1].Value = id;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(ZG_member.Model.consumeSolution model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into consumeSolution(");
            strSql.Append("solutionName,cardTemplateId,consumeSolution1,savingSolution,discountSolution,nextLevelId,levelUp,integralday,taocanxiangqin,cuxiaozhekou,money,leaveDate)");
			strSql.Append(" values (");
            strSql.Append("@solutionName,@cardTemplateId,@consumeSolution1,@savingSolution,@discountSolution,@nextLevelId,@levelUp,@integralday,@taocanxiangqin,@cuxiaozhekou,@money,@leaveDate)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@solutionName", SqlDbType.NVarChar,10),
					new SqlParameter("@cardTemplateId", SqlDbType.Int,4),
					new SqlParameter("@consumeSolution1", SqlDbType.NVarChar,2048),
					new SqlParameter("@savingSolution", SqlDbType.NVarChar,2048),
					new SqlParameter("@discountSolution", SqlDbType.NVarChar,2048),
					new SqlParameter("@nextLevelId", SqlDbType.Int,4),
					new SqlParameter("@levelUp", SqlDbType.Money,8),
                    new SqlParameter("@integralday", SqlDbType.Int,8),
                    new SqlParameter("@taocanxiangqin", SqlDbType.NVarChar,2084),
                    new SqlParameter("@cuxiaozhekou", SqlDbType.Bit),
                    new SqlParameter("@money", SqlDbType.Money,8),
                    new SqlParameter("@leaveDate", SqlDbType.VarChar,50)                 
                                        };
			parameters[0].Value = model.solutionName;
			parameters[1].Value = model.cardTemplateId;
			parameters[2].Value = model.consumeSolution1;
			parameters[3].Value = model.savingSolution;
			parameters[4].Value = model.discountSolution;
			parameters[5].Value = model.nextLevelId;
			parameters[6].Value = model.levelUp;
            parameters[7].Value = model.Integralday;
            parameters[8].Value = model.Taocanxiangqing;
            parameters[9].Value = model.cuxiaozhekou;
            parameters[10].Value = model.money;
            parameters[11].Value = model.leaveDate;
			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ZG_member.Model.consumeSolution model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update consumeSolution set ");
			strSql.Append("solutionName=@solutionName,");
			strSql.Append("cardTemplateId=@cardTemplateId,");
			strSql.Append("consumeSolution1=@consumeSolution1,");
			strSql.Append("savingSolution=@savingSolution,");
			strSql.Append("discountSolution=@discountSolution,");
			strSql.Append("nextLevelId=@nextLevelId,");
			strSql.Append("levelUp=@levelUp,");
            strSql.Append("Integralday=@Integralday,");
            strSql.Append("taocanxiangqin=@taocanxiangqin,");
            strSql.Append("cuxiaozhekou=@cuxiaozhekou,");
            strSql.Append("money=@money,");
            strSql.Append("leaveDate=@leaveDate");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@solutionName", SqlDbType.NVarChar,10),
					new SqlParameter("@cardTemplateId", SqlDbType.Int,4),
					new SqlParameter("@consumeSolution1", SqlDbType.NVarChar,2048),
					new SqlParameter("@savingSolution", SqlDbType.NVarChar,2048),
					new SqlParameter("@discountSolution", SqlDbType.NVarChar,2048),
					new SqlParameter("@nextLevelId", SqlDbType.Int,4),
					new SqlParameter("@levelUp", SqlDbType.Money,8),
                    new SqlParameter("@Integralday", SqlDbType.Int,4),
                    new SqlParameter("@taocanxiangqin", SqlDbType.NVarChar,2048),
                    new SqlParameter("@cuxiaozhekou", SqlDbType.Bit),
                    new SqlParameter("@money", SqlDbType.Money,8),
                     new SqlParameter("@leaveDate", SqlDbType.VarChar,50),
					new SqlParameter("@id", SqlDbType.Int,4)};
			parameters[0].Value = model.solutionName;
			parameters[1].Value = model.cardTemplateId;
			parameters[2].Value = model.consumeSolution1;
			parameters[3].Value = model.savingSolution;
			parameters[4].Value = model.discountSolution;
			parameters[5].Value = model.nextLevelId;
			parameters[6].Value = model.levelUp;
            parameters[7].Value = model.Integralday;
            parameters[8].Value = model.Taocanxiangqing;
            parameters[9].Value = model.cuxiaozhekou;
            parameters[10].Value = model.money;
            parameters[11].Value = model.leaveDate;
			parameters[12].Value = model.id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from consumeSolution ");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
			parameters[0].Value = id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from consumeSolution ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ZG_member.Model.consumeSolution GetModel(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 id,solutionName,cardTemplateId,consumeSolution1,savingSolution,discountSolution,nextLevelId,levelUp,integralday,taocanxiangqin,cuxiaozhekou,money,leaveDate from consumeSolution ");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
			parameters[0].Value = id;

			ZG_member.Model.consumeSolution model=new ZG_member.Model.consumeSolution();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["id"]!=null && ds.Tables[0].Rows[0]["id"].ToString()!="")
				{
					model.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["solutionName"]!=null && ds.Tables[0].Rows[0]["solutionName"].ToString()!="")
				{
					model.solutionName=ds.Tables[0].Rows[0]["solutionName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["cardTemplateId"]!=null && ds.Tables[0].Rows[0]["cardTemplateId"].ToString()!="")
				{
					model.cardTemplateId=int.Parse(ds.Tables[0].Rows[0]["cardTemplateId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["consumeSolution1"]!=null && ds.Tables[0].Rows[0]["consumeSolution1"].ToString()!="")
				{
					model.consumeSolution1=ds.Tables[0].Rows[0]["consumeSolution1"].ToString();
				}
				if(ds.Tables[0].Rows[0]["savingSolution"]!=null && ds.Tables[0].Rows[0]["savingSolution"].ToString()!="")
				{
					model.savingSolution=ds.Tables[0].Rows[0]["savingSolution"].ToString();
				}
				if(ds.Tables[0].Rows[0]["discountSolution"]!=null && ds.Tables[0].Rows[0]["discountSolution"].ToString()!="")
				{
					model.discountSolution=ds.Tables[0].Rows[0]["discountSolution"].ToString();
				}
				if(ds.Tables[0].Rows[0]["nextLevelId"]!=null && ds.Tables[0].Rows[0]["nextLevelId"].ToString()!="")
				{
					model.nextLevelId=int.Parse(ds.Tables[0].Rows[0]["nextLevelId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["levelUp"]!=null && ds.Tables[0].Rows[0]["levelUp"].ToString()!="")
				{
					model.levelUp=decimal.Parse(ds.Tables[0].Rows[0]["levelUp"].ToString());
				}
                if (ds.Tables[0].Rows[0]["levelUp"] != null && ds.Tables[0].Rows[0]["levelUp"].ToString() != "")
                {
                    model.levelUp = decimal.Parse(ds.Tables[0].Rows[0]["levelUp"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Integralday"] != null && ds.Tables[0].Rows[0]["Integralday"].ToString() != "")
                {
                    model.Integralday = int.Parse(ds.Tables[0].Rows[0]["Integralday"].ToString());
                }
                if (ds.Tables[0].Rows[0]["taocanxiangqin"] != null && ds.Tables[0].Rows[0]["taocanxiangqin"].ToString() != "")
                {
                    model.Taocanxiangqing = ds.Tables[0].Rows[0]["taocanxiangqin"].ToString();
                }
                if (ds.Tables[0].Rows[0]["cuxiaozhekou"] != null && ds.Tables[0].Rows[0]["cuxiaozhekou"].ToString() != "")
                {
                    model.cuxiaozhekou = Convert.ToBoolean(ds.Tables[0].Rows[0]["cuxiaozhekou"]);
                }
                if (ds.Tables[0].Rows[0]["money"] != null && ds.Tables[0].Rows[0]["money"].ToString() != "")
                {
                    model.money = Convert.ToDouble(ds.Tables[0].Rows[0]["money"]);
                }
                if (ds.Tables[0].Rows[0]["leaveDate"] != null && ds.Tables[0].Rows[0]["leaveDate"].ToString() != "")
                {
                    model.leaveDate = ds.Tables[0].Rows[0]["leaveDate"].ToString();
                }
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select *");
			strSql.Append(" FROM consumeSolution ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}




		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
            strSql.Append(" id,solutionName,cardTemplateId,consumeSolution1,savingSolution,discountSolution,nextLevelId,levelUp,Integralday,taocanxiangqin,cuxiaozhekou,money,leaveDate ");
			strSql.Append(" FROM consumeSolution ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "consumeSolution";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

